package com.myjob.handlerImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.myjob.common.DubboConfig;
import com.myjob.config.MjServiceName;
import com.myjob.entity.Job;
import com.myjob.handler.JobHandler;
import com.myjob.response.Result;
import com.myjob.service.JobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Chen Yuan
 * @create 2021-03-27  16:59
 */
@Slf4j
@Component
@Service(group = MjServiceName.JOB,
		retries = DubboConfig.RETRIES,
		timeout = DubboConfig.TIME_OUT,
		version = DubboConfig.VERSION)
public class JobHandlerImpl implements JobHandler {
	@Autowired
	private JobService jobService;

	@Override
	public Result deleteJobs(String hrId) {
		QueryWrapper<Job> wrapper = new QueryWrapper<>();
		wrapper.eq("hr_id", hrId);
		boolean remove = jobService.remove(wrapper);
		if (remove) {
			return Result.succeed("删除成功");
		}else {
			return Result.failed("删除失败");
		}
	}

	@Override
	public Result deleteJobListByHrIds(List<String> hrIds) {
		QueryWrapper<Job> wrapper = new QueryWrapper<>();
		wrapper.in("hr_id", hrIds);
		boolean remove = jobService.remove(wrapper);
		if (remove){
			return Result.succeed("删除成功");
		}else {
			return Result.failed("删除失败");
		}
	}

	@Override
	public Result updateJobByHrIds(List<String> hrIds, String jobStatus) {
		UpdateWrapper<Job> wrapper = new UpdateWrapper<>();
//		log.info("======"+hrIds+". =="+jobStatus);
		wrapper.in("hr_id", hrIds);
		Job job = new Job();
		job.setJobStatus(jobStatus);
		boolean update = jobService.update(job, wrapper);
		if (update){
			return Result.succeed("修改成功");
		}else {
			return Result.failed("修改失败");
		}
	}


}
